import pygame,sys
import game_function as gf
from settings import Settings
from ship import Ship
from pygame.sprite import Group
from alien import Alien
from game_stats import GameStats
from button import Button
from scoreboard import Scoreboard


def run_game():
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
                                (ai_settings.
                                      screen_width,
                                      ai_settings.screen_height)
                                     ,depth=0)
    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings,
                    screen,
                    stats)
    pygame.display.set_caption("Roge Austine Aliens Invasion")
    play_button = Button(ai_settings,
                         screen,
                         "Commence")
    ################################## 
    ship = Ship(screen,ai_settings)
    bullets = Group()
    aliens = Group()

    while True:
        gf.check_events( ai_settings,
                         screen,
                         stats,
                         sb,
                         play_button,
                         ship,
                         aliens,
                         bullets,)
        if stats.game_active > 0:
            ship.update()
            bullets.update()
            # Update the positions
            gf.update_bullets(ai_settings,
                              screen,
                              stats,
                              sb,
                              ship,
                              aliens,
                              bullets)
            gf.update_aliens(ai_settings,
                              stats,
                              screen,
                              sb,
                              ship,
                              aliens,
                              bullets)

        gf.update_screen(ai_settings,
                         screen,
                         stats,
                         sb,
                         ship,
                         aliens,
                         bullets,
                         play_button)

if __name__ == '__main__':
    run_game()

































